<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Administrator extends Model
{
    use HasFactory;

    protected $table = 'zfm_Administrator';


    /**
     *  '展示数据
     * @return Administrator[]|\Illuminate\Database\Eloquent\Collection
     */
    public static function showList()
    {
        return self::paginate(4);
    }

    /**
     * 搜索方法
     * @param $data
     */
    public static function search($username, $data)
    {
        return self::where($username, 'like', "%$data%")->get(['name', 'location', 'rent', 'created_at']);
    }

    /**
     * 删除数据
     */
    public static function del($id)
    {
        return self::query()->delete();
    }

    /**
     * 查找对应的数据
     */
    public static function upDateFind($id)
    {
        return self::query()->where('id', $id)->first();
    }

    /**
     * 修改数据
     */
    public static function upDatHouse($data)
    {
        try {
            return static::where('id', $data['id'])->update([
                'name' => $data['name'],
                'location' => $data['location'],
                'rent' => $data['rent'],
            ]);
        } catch (\Exception $exception) {
            return false;
        }
    }
}
